package com.api.gbhg.huangwm.dao;

import com.customization.commons.LogTool;
import weaver.conn.RecordSet;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Huangwm
 * @Date 2021-11-21
 * @Version 1.0
 * @Description TODO 支出预算相关数据操作
 **/
public class ExpendBudgetDButils {

    private LogTool logTool = new LogTool("/log/gbhg/huangwm/dao/ExpendBudgetDButils",false);

    /**
     * 根据流程id获取流程表名
     * @param workflowId
     * @return
     */
    public String getWorkflowTabNameByWfid(String workflowId){
        RecordSet rs = new RecordSet();
        String sql = "select tablename from workflow_bill where id = (select formid from workflow_base where id = "+workflowId+")";
        rs.executeQuery(sql);
        rs.next();
        return rs.getString("tablename");
    }

    /**
     * 根据流程主表id获取流程明细表名称列表
     * @param maindId
     * @return
     */
    public static List<String> getDetailTables(int maindId) {
        List<String> resList = new ArrayList<>();
        RecordSet rs = new RecordSet();
        rs.executeQuery("select d.tablename from workflow_billdetailtable d where d.billid=" + maindId + ";");
        while (rs.next()) {
            resList.add(rs.getString("tablename"));
        }
        return resList;
    }

    /**
     * 查询单位名称
     * @param id
     * @return
     */
    public String getSubcompanyNameById(String id){
        RecordSet rts=new RecordSet();
        String sql="select subcompanyname from hrmsubcompany where id="+id;
        rts.executeQuery(sql);
        rts.next();
        return rts.getString("subcompanyname");
    }

    /**
     * 查询科室名称
     * @param id
     * @return
     */
    public String getDepartmentNameById(String id){
        RecordSet rts=new RecordSet();
        String sql="select departmentname from HrmDepartment where id="+id;
        rts.executeQuery(sql);
        rts.next();
        return rts.getString("departmentname");
    }

    /**
     * 查询用户名称
     * @param id
     * @return
     */
    public String getUserNameById(String id){
        RecordSet rts=new RecordSet();
        String sql="select lastname from hrmresource where id="+id;
        rts.executeQuery(sql);
        rts.next();
        return rts.getString("lastname");
    }

    /**
     * 根据流程配置id，获取流程表id
     * @param workFlowId 流程配置id
     * @return
     */
    public int getFlowTableLableId(String workFlowId) {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select w.formid from workflow_base w where w.id=" + workFlowId);
        rs.next();
        return rs.getInt("formid");
    }
}
